import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:tiktokadult/hj_model/user/user_income_info_model.dart';
import 'package:tiktokadult/hj_utils/api_service/mine_service.dart';

import '../../../hj_model/mine/promotion_record.dart';

class MineShareRecordLogic extends GetxController {
  MineShareRecordLogic get to => Get.find<MineShareRecordLogic>();

  RefreshController? refreshController;
  final promotionList = <Promotion>[];
  bool isLoading = true;

  int total = 0;

  int currentPage = 1;
  UserIncomeModel? model;

  @override
  void onReady() {
    super.onReady();
    loadInfo();
    loadData();
  }

  void loadInfo() async {
    model = await MineService.fetchAllIncomeInfo();
    update();
  }

  void loadData({bool isRefresh = true, int size = 10}) async {
    if (isRefresh) {
      currentPage = 1;
    }
    final retValue = await MineService.getProxyBindRecord(size, currentPage);
    isLoading = false;

    if (isRefresh) {
      total = retValue?.total ?? 0;
      promotionList.clear();
      refreshController?.refreshCompleted();
    }

    if (retValue?.hasNext == true) {
      refreshController?.loadComplete();
    } else {
      refreshController?.loadNoData();
    }
    promotionList.addAll(retValue?.list ?? []);
    currentPage += 1;
    update();
  }
}
